import Cookies from 'js-cookie'

const app = {
  state: {
    sidebar: {
      opened: true
    },
    language: Cookies.get('language') || 'en',
    departTree:[],
    allRoles:[],
    isRoleChange:false,
    isRoleChoice:false,
    ispTreeChange:false,
    ispTreeDelete:false,
    normalPermissions:[],
    otherPermissions:[],
    sessionValid:false,
    currentUserId:'',
    currentUserInfo:'',
    entityList:[],
    partyList:null,
    isPartyMemberChange:false,
    isEntityMemberChange:false,
    isCustomerVipChange:false,
    currentEvaluateItemDetail:{},
    currentEvaluateItemProgress:{},
  },
  mutations: {
    TOGGLE_SIDEBAR: state => {
      state.sidebar.opened = !state.sidebar.opened
    },
    SET_LANGUAGE: (state, language) => {
      state.language = language
      // Cookies.set('language', language)
    },
    SET_DEPARTTREE: (state, departtree) => {
      state.departTree = departtree
      // Cookies.set('departTree', departtree)
    },
    SET_PARTY_LIST: (state, partyList) => {
      state.partyList = partyList
      // Cookies.set('departTree', departtree)
    },
    SET_ALL_ROLES: (state, allRoles) => {
      state.allRoles = allRoles
      // Cookies.set('allRoles', allRoles)
    },
    SET_IS_ROLE_CHANGE: (state, isRoleChange) => {
      state.isRoleChange = isRoleChange
      // Cookies.set('isRoleChange', isRoleChange)
    },
    SET_IS_ROLE_CHOICE: (state, isRoleChoice) => {
      state.isRoleChoice = isRoleChoice
      // Cookies.set('isRoleChoice', isRoleChoice)
    },
    SET_NOEMAL_PERMISSIONS: (state, normalPermissions) => {
      state.normalPermissions = normalPermissions
      // Cookies.set('normalPermissions', normalPermissions)
    },
    SET_OTHER_PERMISSIONS: (state, otherPermissions) => {
      state.otherPermissions = otherPermissions
      // Cookies.set('otherPermissions', otherPermissions)
    },
    SET_IS_PTREE_CHANGE: (state, ispTreeChange) => {
      state.ispTreeChange = ispTreeChange
      // Cookies.set('ispTreeChange', ispTreeChange)
    },
    setSessionValid: (state, svid) => {
      state.sessionValid = svid
      // Cookies.set('sessionValid', svid)
    },
    setCurrentUserId: (state, cuid) => {
      state.currentUserId = cuid;
    },
    setCurrentUserInfo: (state, cuinfo) => {
      state.currentUserInfo = cuinfo;
      // Cookies.set('currentUserInfo', cuinfo)
      // window.localStorage.setItem('currentUserInfo', JSON.stringify(cuinfo));
    },
    SET_ENTITYLIST: (state, list) => {
      state.entityList = list
      // window.localStorage.setItem('entityList', JSON.stringify(list));
    },
    SET_IS_PARTY_DELETE: (state, ispTreeDelete) => {
      state.ispTreeDelete = ispTreeDelete
    },
    SET_PARTY_MEMBER_CHANGE: (state, isPartyMemberChange) => {
      state.isPartyMemberChange = isPartyMemberChange
    },
    SET_ENTITY_MEMBER_CHANGE: (state, isEntityMemberChange) => {
      state.isEntityMemberChange = isEntityMemberChange
    },
    SET_CUSTOM_VIP_CHANGE: (state, isCustomerVipChange) => {
      state.isCustomerVipChange = isCustomerVipChange
    },
    SET_CURRENT_EVA_ITEM_DEYAIL: (state, ceid) => {
      state.currentEvaluateItemDetail = ceid;
    },
    SET_CURRENT_EVA_ITEM_PROGRESS: (state, ceip) => {
      state.currentEvaluateItemProgress = ceidp;
    },
  },
  actions: {
    toggleSideBar({ commit }) {
      commit('TOGGLE_SIDEBAR')
    },
    setLanguage({ commit }, language) {
      commit('SET_LANGUAGE', language)
    },
    setDepartTree({ commit }, departtree) {
      commit('SET_DEPARTTREE', departtree)
    },
    setPartyList({ commit }, partyList) {
      commit('SET_PARTY_LIST', partyList)
    },
    setAllRoles({ commit }, allRoles) {
      commit('SET_ALL_ROLES', allRoles)
    },
    setIsRoleChange({ commit }, isRoleChange) {
      commit('SET_IS_ROLE_CHANGE', isRoleChange)
    },
    setIsRoleChoice({ commit }, isRoleChoice) {
      commit('SET_IS_ROLE_CHOICE', isRoleChoice)
    },
    setNormalPermissions({ commit }, normalPermissions) {
      commit('SET_NOEMAL_PERMISSIONS', normalPermissions)
    },
    setOtherPermissions({ commit }, otherPermissions) {
      commit('SET_OTHER_PERMISSIONS', otherPermissions)
    },
    setIspTreeChange({ commit }, ispTreeChange) {
      commit('SET_IS_PTREE_CHANGE', ispTreeChange)
    },
    setSessionValid({ commit }, sessionValid) {
      commit('setSessionValid', sessionValid)
    },
    setCurrentUserId({ commit }, cuid) {
      commit('setCurrentUserId', cuid)
    },
    setCurrentUserInfo({ commit }, cuinfo) {
      commit('setCurrentUserInfo', cuinfo)
    },
    setEntityList({ commit }, list) {
      commit('SET_ENTITYLIST', list)
    },
    setTreeDelete({ commit }, ispTreeDelete) {
      commit('SET_IS_PARTY_DELETE', ispTreeDelete)
    },
    setPartyMemberChange({ commit }, isPartyMemberChange) {
      commit('SET_PARTY_MEMBER_CHANGE', isPartyMemberChange)
    },
    setEntityMemberChange({ commit }, isEntityMemberChange) {
      commit('SET_ENTITY_MEMBER_CHANGE', isEntityMemberChange)
    },
    setCustomerVipChange({ commit }, isCustomerVipChange) {
      commit('SET_CUSTOM_VIP_CHANGE', isCustomerVipChange)
    },
    setCurrentEvaluateItemDetail({ commit }, currentEvaluateItemDetail) {
      commit('SET_CURRENT_EVA_ITEM_DEYAIL', currentEvaluateItemDetail)
    },
    setCurrentEvaluateItemProgress({ commit }, currentEvaluateItemProgress) {
      commit('SET_CURRENT_EVA_ITEM_PROGRESS', currentEvaluateItemProgress)
    },
  }
}

export default app
